package com.hlhj.funlike_business.moudle;

import android.content.Context;

import com.example.mymvp.mvp.BaseModule;
import com.example.mymvp.okrx.BaseAciton;
import com.hlhj.funlike_business.api.Apis;
import com.hlhj.funlike_business.api.BaseObser;
import com.hlhj.funlike_business.bean.ActivityBean;
import com.hlhj.funlike_business.bean.MsgBean;
import com.lzy.okgo.model.Response;

import java.util.List;

public class PreferentialMoudle implements BaseModule{
    public interface getAddResult{
        void showResult(String msg);

        void showList(List<ActivityBean.DataBean> dataBeans);
    }

    public getAddResult listener;

    public void setListener(getAddResult listener) {
        this.listener = listener;
    }

    public void LoadAddActivity(Context context,String condition,String activity_value){
        Apis.INSTANCE.AddActivity(condition,activity_value)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (listener!=null){
                            listener.showResult(msgBeanResponse.body().getMsg());
                        }
                    }
                });
    }

    public void LoadDelActivity(Context context,int id){
        Apis.INSTANCE.DelActivity(id)
                .subscribe(new BaseObser<Response<MsgBean>>(context) {
                    @Override
                    public void httpSuccess(Response<MsgBean> msgBeanResponse) {
                        if (listener!=null){
                            listener.showResult(msgBeanResponse.body().getMsg());
                        }
                    }
                });
    }

    public void getActivityList(Context context){
        Apis.INSTANCE.GetActivityList()
                .subscribe(new BaseObser<Response<ActivityBean>>(context) {
                    @Override
                    public void httpSuccess(Response<ActivityBean> activityBeanResponse) {
                        if (listener!=null){
                            listener.showList(activityBeanResponse.body().getData());
                        }
                    }
                });
    }
}
